package com.booth.manage.controllers;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.booth.base.controllers.BaseController;
import com.booth.base.model.Users;
import com.booth.base.utils.ResultStatus;
import com.booth.manage.model.BoothPayLog;
import com.jfinal.plugin.activerecord.Db;

/***
 *     摊位缴费录入控制器
 * @author admin
 *
 */
public class BoothPayLogController extends BaseController {
	private boolean success = false;
	
	private final static String BASE_PAGE_URL = "booth_pay_log";
	
	
	public void list() {
		Users curUser = super.getCurUser();
		Integer applyId = Integer.MIN_VALUE;
		if(curUser.getGroupType() != null &&  curUser.getGroupType() == GROUP_TYPE_3) {
			applyId = curUser.getUserId();
		}
		String sql = "select t.*,a.`name` as booth_name,a.area,a.num,a.address,b.user_name as buss_name from booth_pay_log t \n" + 
				"left join booth a on t.b_id = a.id\n" + 
				"left join booth_progress c on t.b_id = c.booth_id and c.progress_status = 1\n" +
				"left join users b on t.o_id = b.user_id\n"
				+ "where t.b_id = ? ";
		if(applyId != Integer.MIN_VALUE){
			sql += " and t.o_id = "+applyId;
		}
		setAttr("rows", Db.find(sql, new Object[] {getParaToInt("b_id")}));
		renderResult(ResultStatus.SUCCESS);
	}
	

	public void doInputPay() {
		List<String> url = super.uploads("pay_img");
		System.out.println("url=:"+url);
		Users u = getCurUser();
		BoothPayLog item = getModel(BoothPayLog.class);
		item.set("pay_img", url != null && !url.isEmpty() ? JSON.toJSONString(url) : null);
		setCreator(item, u);
		success = item.save();
		if (success){
			renderResult(ResultStatus.SUCCESS);
		}
		else
			renderResult(ResultStatus.ADD_FAILURL);
	}

}
